// pages/customer/customer.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: '',
    iconSize: 15,
    keyword: '',
    orderType:'',
    tabIndex: 0,
    orderData: ['在线购', '到店购', '全部'],
  },
  tabTap: function (e) {
    var that = this;
    var idx = e.currentTarget.dataset.idx;
    that.setData({
      tabIndex: e.currentTarget.dataset.idx,
    })
    if (idx == 2){
      app.post('/shop/orderList').then(res => {
        that.setData({
          data: res,
        })
      });
    }else{
      var orderType = idx + 1;
      app.post('/shop/orderList', {
        type: orderType
      }).then(res => {
        that.setData({
          data: res,
        })
      });
    }
    console.log(that.data.tabIndex);
  },
  onShow: function() {
    this.getOrder();
  },
  getOrder: function() {
    let that = this;
    app.post('/shop/orderList', {
      type: 1
    }).then(res => {
      console.log(res)
      that.setData({
        data: res,
      })
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 判断图标大小
    this.setData({
      iconSize: wx.getSystemInfoSync().windowWidth / 375 * 15
    })
    // console.log(this.data.iconSize)
  },
  inputSearch: function(e) {
    let keyword = e.detail.value;
    console.log(keyword)
    let that = this;
    app.post('/shop/searchOrderManage', {
      keyword: keyword
    }).then(res => {
      that.setData({
        data: res,
      })
    });
  },
  clearInputSearch: function(e) {
    this.setData({
      keyword: ''
    });
    this.getOrder();
  },
  orderDetail:function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: './order-detail/order-detail?id='+id,
    })
  }
})